var express = require('express');  //生成一个express实例 app
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

//var routes = require('./routes/index');//不通过start中间跳转
var routes = require('./routes/route');  
var app = express();

// view engine setup
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');



// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));  //加载日志中间件
app.use(bodyParser.json());   //加载解析json的中间件
app.use(bodyParser.urlencoded({ extended: false }));  //加载解析urlencoded请求体的中间件。
app.use(cookieParser());  //加载解析cookie的中间件。
app.use(express.static(path.join(__dirname, 'public')));  //设置public文件夹为存放静态文件的目
app.use(express.static(path.join(__dirname, 'build')));
//路由控制器
// app.use('/', routes);
// app.use('/users', users);
//routes(app);    //不通过start中间跳转
routes.start(app);

app.listen(app.get('port'), function() {
  console.log('Express server listening on port ' + app.get('port'));
});

module.exports = app;